package main

import (
	"fmt"
	"sync"
	"time"
)

//定义一个channel，传输的数据类型为string
var ch chan string
var wg sync.WaitGroup

func send_msg() {

	fmt.Println("I am goroutine send_msg")
	//time.Sleep(time.Second * 5) //睡5s
	ch <- "hello" //向channel写数据
	fmt.Println("I am goroutine send_msg, over")
	wg.Done()
}

func main() {
	//创建channel,channel一定要创建，使用make
	//channel也是一种变量
	ch = make(chan string) //创建无缓冲区channel
	wg.Add(1)
	go send_msg()
	fmt.Println("begin read channel, wait duo shao miao?")
	time.Sleep(time.Second * 3)
	msg := <-ch //从channel读取数据
	fmt.Println(msg)
	wg.Wait()
}
